/*
 * InfosetFactory.java
 *
 * Created on February 23, 2005, 7:58 AM
 */

package org.infoset.xml;

import java.net.*;

/**
 *
 * @author R. Alexander Milowski
 */
public class InfosetFactory
{
   static Class infosetClass;
   static Infoset defaultInfoset;
   static {
      try {
         String className = System.getProperty("org.infoset.xml.Implementation","org.infoset.xml.memory.MemoryInfoset");
         infosetClass = Class.forName(className);
      } catch (Exception ex) {
         System.err.println("Cannot load infoset implementation!!!");
         ex.printStackTrace();
      }
      try {
         defaultInfoset = newInfoset();
      } catch (XMLException ex) {
         ex.printStackTrace();
      }
   }
   
   /** Creates a new instance of InfosetFactory */
   protected InfosetFactory()
   {
   }
   
   public static Infoset newInfoset() 
      throws XMLException
   {
      try {
         return (Infoset)infosetClass.newInstance();
      } catch (Exception ex) {
         throw new XMLException("Cannot create instance due to class error.",ex);
      }
   }
   
   public static Infoset getDefaultInfoset() {
      return defaultInfoset;
   }
   
   public static Name createName(String localName) {
      return defaultInfoset.createName(localName);
   }
   
   public static Name createName(URI ns,String localName) {
      return defaultInfoset.createName(ns,localName);
   }

   public static URI createNamespace(String uri) {
      try {
         return defaultInfoset.createNamespace(uri);
      } catch (URISyntaxException ex) {
         throw new RuntimeException("Bad static URI initialization: "+uri,ex);
      }
   }
   
}
